'''
	Helper functions for DOM usage
	
	@author: S.G. Epskamp
'''

def SetAttributes(elem, names, values):
	'''
		Helper function to add multiple attributes to DOM element. First tuple holds names
		i.e. ('x','y') and the second holds values i.e. (12,23)
	'''
	assert len(names) == len(values)
	for name, value in zip(names, values):
		elem.setAttribute(name, str(value))


def readAttributes(elem, names):
	'''
		Get a tuple of all the attributes in tuple names,
		of false if one isn't found
		All attributes are being cast to float is appropriate	
	'''
	values = []
	for name in names:
		if elem.hasAttribute(name):
			try:
				values.append(float(elem.getAttribute(name)))
			except ValueError:
				values.append(elem.getAttribute(name))
		else:
			print 'attr not found', name
			return None
	return values
		